<%@page import="org.pewpew.model.WorldState"%>
<%@page import="org.pewpew.model.Player"%>
<%@page import="org.pewpew.server.Persistence"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.io.PrintStream"%>
<%@page contentType="text/html;charset=UTF-8" language="java"%>
<%
	Throwable lastError = null;
	try {
		String json = request.getParameter("json");
		if (json != null) {
			Player player = Player.fromJSON(json);
			WorldState worldState = Persistence.getWorldState();
			worldState.addObject(player);
			Persistence.saveWorldState(worldState.toJSON());
		}
	} catch (Throwable e) {
		lastError = e;
	}
%>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
	var refreshId = setInterval(function() {
		alert ("Started");
		$('#worldState').fadeOut("slow").load(
				'http://pewpew-server.appspot.com/get-world-state').fadeIn(
				"slow")
;
}, 5000);
</script>
</head>
<body>
	<div id="worldState"></div>

	<form action="admin.jsp" method="POST">
		JSON<br/>
		<textarea rows="10" cols="40" name="json" ></textarea>
		<input type="submit" value="add object" />
	</form>

	<div>
		<%
			if (lastError != null) {
				lastError.printStackTrace(response.getWriter());
			}
		%>
	</div>
</body>
</html>